package com.tiza.xiaoyoubao.ui.fragment;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.tianze.library.base.BaseFragment;
import com.tiza.xiaoyoubao.R;
import com.tiza.xiaoyoubao.app.Constants;
import com.tiza.xiaoyoubao.app.UIHelper;
import com.tiza.xiaoyoubao.entity.MpMGJTaskOrderInfo;
import com.tiza.xiaoyoubao.entity.UserInfo;
import com.tiza.xiaoyoubao.utils.DateUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mapple on 17/4/11.
 */

public class MpMGJTaskDetialFragment extends BaseFragment {

    @BindView(R.id.tv_userId)
    TextView tv_userId;
    @BindView(R.id.tv_taskId)
    TextView tv_taskId;
    @BindView(R.id.tv_taskMoney)
    TextView tv_taskMoney;
    @BindView(R.id.tv_money)
    TextView tv_money;
    @BindView(R.id.tv_type)
    TextView tv_type;
    @BindView(R.id.tv_orderNum)
    TextView tv_orderNum;
    private MpMGJTaskOrderInfo mOrderInfo;
    UserInfo userInfo = Hawk.get(Constants.KEY_USER_INFO, (UserInfo) null);

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mp_mgj_detial;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        mOrderInfo = (MpMGJTaskOrderInfo) args.getSerializable("info");
        if (null == mOrderInfo) {
            toast("详情加载失败");
            finish();
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        tv_userId.setText(userInfo.getWebzzCmsBuyerInfo().getTelphone());
        tv_orderNum.setText("(今日可接单"+mOrderInfo.getTastNumber()+"笔)");
        tv_taskId.setText("ID:" + mOrderInfo.getUserId());
        tv_money.setText(DateUtils.formateRate(mOrderInfo.getBaseCmi()));
        tv_taskMoney.setText(mOrderInfo.getPrice() + "元");
        tv_type.setText(mOrderInfo.getBackName());
    }

    @OnClick({R.id.view_order})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.view_order:
                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setTitle("提示");
                String message = "确认使用" + userInfo.getWebzzCmsBuyerInfo().getTelphone() + "接任务吗?\n接单2小时内必须完成任务操作," +
                    "否则将扣除1金,如果5分钟内取消不扣金";
                builder.setMessage(message);
                builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 隐藏当前对话框
                        UIHelper.showMpMGJAttention(mActivity);
                        dialog.dismiss();
                    }
                });

                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 隐藏当前对话框
                        toast("取消");
                        dialog.dismiss();
                    }
                });

                builder.create().show();
                break;
            default:
                break;
        }
    }
}
